package com.gitee.qdbp.jdbc.operator.where;

import com.gitee.qdbp.able.jdbc.model.LikeValue;
import com.gitee.qdbp.jdbc.api.SqlBoot;
import com.gitee.qdbp.jdbc.operator.DbBinaryOperator;
import com.gitee.qdbp.jdbc.operator.base.DbAbstractOperator;
import com.gitee.qdbp.jdbc.sql.SqlBuffer;
import com.gitee.qdbp.jdbc.sql.SqlTools;

/**
 * 二元StartsWith运算符
 *
 * @author zhaohuihua
 * @version 20200123
 */
public class DbBinaryStartsWithOperator extends DbAbstractOperator implements DbBinaryOperator {

    /** 版本序列号 **/
    private static final long serialVersionUID = 1L;

    public DbBinaryStartsWithOperator() {
        super("Starts With", "StartsWith", "Starts");
    }

    @Override
    public SqlBuffer buildSql(String columnName, Object columnValue, SqlBoot sqlBoot) {
        if (columnValue instanceof LikeValue) {
            throw new IllegalArgumentException("StartsWith not support 'LikeValue', please use 'like'.");
        }
        String stringValue = columnValue == null ? null : SqlTools.unwrapDbVariable(columnValue).toString();
        return sqlBoot.newSqlBuilder().ad(columnName).ad(sqlBoot.sqlDialect().buildStartsWithSql(stringValue)).out();
    }

}
